<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>我的信息</title>
    <link rel="stylesheet" type="text/css" href="../css/api.css"/>
    <link rel="stylesheet" type="text/css" href="../css/weui.css"/>
    <link rel="stylesheet" type="text/css" href="../css/style.css"/>
    <script src="../script/jquery-3.2.1.js"></script>
    <script src="../script/switch.js"></script>
    <script src="../script/api.js"></script>
    <style>

    </style>
</head>
<!-- 主界面 -->
<body ontouchstart>
    <div class="empty" id = "apiNode"></div>
    <br/>
    <br/>
    <a href="../html/frame3.html" style="width: 100%">
    	<button class="weui_btn weui_btn_primary" style="background-color: #18b4ed;width: 80% ">点击添加身份信息</button>
    </a>
	<br/>
</body>
</html>
<script type="text/javascript">
var urlStr= "101.207.250.6:8520";
apiready = function(){
	crossDomainRequest();
	 var param = {};
    param.loadingImgae = './image/loading_more.gif'; //定义刷新小箭头的图片
    param.bgColor = '#ccc';                            //定义下拉刷新区域的背景
    param.textColor = '#fff';                          //定义下拉刷新提示文字的颜色
    param.textDown = '下拉刷新';                     //定义下拉刷新文字
    param.textUp = '松开立即刷新...';                       //定义松开刷新文字
    param.showTime = false;                             //定义是否显示最后一次刷新时间
    api.setRefreshHeaderInfo(param, function(ret, err){
        toDoRequest();
    });
};
function toDoRequest(){
        api.refreshHeaderLoadDone();        //复位下拉刷新
		location.reload();
}
	var account = $api.getStorage("dl_phone");  
	  //var account ='18080801071';
    function crossDomainRequest() {
        var url = 'http://www.scscpt.com:8520/wzrz/getappguestinfo';
    	api.ajax({
		    url: url,
		    method: 'post',
		    dataType: 'text',
		    header:{
		    	'Content-Type':'application/x-www-form-urlencoded;charset=utf-8'
		    },
		    data: {
		    	values:{
		            account:account
		    	}
		    }
		}, function(ret, err) {
		    if (ret) {
		    	var MSG5 = JSON.stringify(ret) ;	    	
          		liMsg(MSG5);		
		    } else {
		        api.alert({ msg: JSON.stringify(err) });
		    }
		});    
    }
    /*
    //发起以保存的身份信息请求
    function crossDomainRequest() {
      if (xhr) {
        xhr.open('POST', url, true);
        xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        xhr.onreadystatechange = handler;
        xhr.send("account=18190925709");
      } else {
      }
    }
    //以保存身份信息请求处理
    function handler(evtXHR) {
      if (xhr.readyState == 4) {
        if (xhr.status == 200) {
          var response = xhr.responseText;
          liMsg(response);

        } else {
          //alert("不允许跨域请求。");
        }
      }
      else {     
      }
    }
    */
    //动态列出从服务器上获取到的该账号下的所有身份信息内容
    function liMsg(response){
   		var str = response.split("*");
        if(str[1]!="</string>"){
      	for(var i=1;i<str.length-1;i++){
      		var msg = str[i].split("|");
      		var countid = msg[0]
			var name = msg[1];
			var cardno = msg[2];
			var code = msg[3];
			var gender = msg[4];
			gender = switchGender(gender);
			var birth = msg[5];
			var address = msg[6];
			var nation  = switchNation(code);
			var secNo = secCardNo(cardno);
			var box = document.getElementById("apiNode");
			var li = document.createElement("div"); 
			li.style.textAlign = "left";
			li.style.marginLeft = "20px";
			li.innerHTML = 
				'<div class="weui_cells_title">身份信息：</div>'+
				'<div class="weui_cells" style="font-size:12px ;width:95%">'+
        			'<div class="weui_cell" >'+
            			'<div class="weui_cell_bd weui_cell_primary">'+
                		'<p>'+"姓&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;名："+name+'<br/>'+
                		"身份证号："+secNo+'<br/>'+
                		"民&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;族："+nation+'<br/>'+
                		"性&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;别："+gender+'<br/>'+
                		"出生日期："+birth+'<br/>'+
                		"详细住址："+address+'</p>'+
            			'</div>'+
        			'</div>'+
	    			'<div style="float:left;width: 100%;">'+    			
	        			'<a style="width:25%;float=left;margin:10px">'+
	        			'<button class="weui_btn weui_btn_primary" id="'+countid+'"'+
	        			'style="width: 100%;float=left;font-size:14px;background-color:#FFD700" onclick=del(this)>删除</button>'+
	        			'</a>'+
	        			'<a style="width:25%;float=left;margin:10px">'+
	        			'<button class="weui_btn weui_btn_primary" id="'+countid+'"'+
	        			'style="width: 100%;float=left;font-size:14px" onclick=update(this)>修改</button>'+
        				'</a>'+
						'<a style="width:25%;float=left;margin:10px">'+
						'<button class="weui_btn weui_btn_primary" id="'+countid+'" style="background-color:'+ 
						'#18b4ed;width: 100%;font-size:14px;" onclick="scanSingle(this)">入住</button>'+
	        			'</a>'+
	    			'</div>'+
	    			/*
	    			'<div style="float:left;width: 100%">'+    			
	        			'<button  id="'+countid+'"'+
	        			'style="width: 20%;height:20px;float=left;;font-size:14px" onclick=del(this)>删除</button>'+
	        			'<button  id="'+countid+'"'+
	        			'style="width: 20%;height:20px;float=left;;font-size:14px" onclick=update(this)>修改</button>'+
						'<button  id="'+countid+'" style="background-color:'+ 
						'#18b4ed;width: 40%;height:20px;font-size:14px;" onclick="scanSingle(this)">使用该身份信息入住</button>'+
	    			'</div>'+
	    			*/
    			'</div>';
			box.appendChild(li);  
      	}
      	
      }
    }
    //删除身份信息
    function del(obj){
    	event.returnValue = confirm("删除是不可恢复的，你确认要删除吗？");
    	if(event.returnValue){
			var url = 'http://www.scscpt.com:8520/wzrz/delappguestinfo';
    	api.ajax({
		    url: url,
		    method: 'post',
		    dataType: 'text',
		    header:{
		    	'Content-Type':'application/x-www-form-urlencoded;charset=utf-8'
		    },
		    data: {
		    	values:{
		            id:obj.id
		    	}
		    }
		}, function(ret, err) {
		    if (ret) {
		    	var MSG5 = JSON.stringify(ret) ;	    	
          		liMsg(MSG5);		
		    } else {
		        api.alert({ msg: JSON.stringify(err) });
		    }
		}); 
		/*       	
    		var uri = 'http://'+urlStr+'/Service1.asmx/delAppGuestInfo';
	        xhr.open('POST', uri, true);
	        xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	        xhr.onreadystatechange = handler;
	        xhr.send("id="+obj.id);
	        */
    	}else{
    	}
    	location.reload();
    }
    //修改身份信息，获取身份信息id跳转到身份信息添加页面fram3
    function update(obj){
    	var id = obj.id;
    	window.location.href="../html/frame3.html?id="+id;
    		
    }
    var Sid="";
    //扫描二维码
	function scanSingle(obj){
		Sid = obj.id;
        var FNScanner = api.require('FNScanner');
		FNScanner.openScanner({
	    	autorotation: true,   
			},function( ret, err ){        
	    		if( ret ){
	        		if (ret.eventType == 'success') {
						var info = ret.content;
						gethotleinfo(info);
						//
					} else if (ret.eventType == 'fail') {
	                }
	            }else{
	                api.toast({msg:err.msg});
	            }
	        });
	}
	
	//二维码信息上传服务器
	/*function gethotleinfo(info){
	var hotleName ='金穗测试';
	var taxcode = '5101000562';
	window.location.href="../html/frame2.html?id="+Sid+"&hotleName="+hotleName+"&taxcode="+taxcode;
	}
	*/
 	function gethotleinfo(info){
 			api.showProgress({
   				style: 'default',
   				 animationType: 'fade',
   				 title: '二维码扫描...',
   				 text: '请耐心等待...',
   				 modal: false
			});
		var i = info.indexOf("invoiceMerId");
		var end = info.indexOf("&invoiceUserId");
		info = info.substring(i,end);
		i = info.indexOf("=");
		info = info.substring(i+1);
		api.ajax({
		    url: 'http://www.scscpt.com:8520/wzrz/gethotleinfo',
		    method: 'post',
		    dataType: 'text',
		    header:{
		    	'Content-Type':'application/x-www-form-urlencoded;charset=utf-8'
		    },
		    data: {
		    	values:{
		            secid: info
		    	}
		    }
		}, function(ret, err) {
		    if (ret) {
		    	var MSG5 = JSON.stringify(ret) ;	    	
		        var msg = MSG5.split('*');
	            var hotleName = msg[2];
	            var taxcode = msg[1];
	            api.hideProgress();
	            if(hotleName!=null && taxcode!=null){
				window.location.href="../html/frame2.html?id="+Sid+"&hotleName="+encodeURI(encodeURI(hotleName))+"&taxcode="+taxcode;
				}else{
					alert("获取二维码信息失败！");
				}
		    } else {
		        api.alert({ msg: JSON.stringify(err) });
		    }
		});
	}
	

	
	/*
	function gethotleinfo(info){
		var i = info.indexOf("invoiceMerId");
		var end = info.indexOf("&invoiceUserId");
		info = info.substring(i,end);
		i = info.indexOf("=");
		info = info.substring(i+1);
  		var uri = 'http://'+urlStr+'/Service1.asmx/getHotleInfo';
		if (xhr) {
	        xhr.open('POST', uri, true);
	        xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	        xhr.onreadystatechange = handler2;
	        xhr.send("secid="+info);
	    } else {
	    }
	    
	}
	//获取旅馆信息，跳转到fram2
	function handler2(evtXHR) {
	if (xhr.readyState == 4) {
		if (xhr.status == 200) {
            var response = xhr.responseText;
            var msg = response.split('*');
            var hotleName = msg[2];
            var taxcode = msg[1];
			window.location.href="../html/frame2.html?id="+Sid+"&hotleName="+hotleName+"&taxcode="+taxcode;
        	//window.location.href="../html/frame2.html?id=5101000562&hotleName=xxxxx&taxcode=5101000562";
        } else {
          //alert("不允许跨域请求。");
        }
      }
      else {     
      }
    }
    */
    
</script>












